class Product < ActiveRecord::Base
  validates_presence_of :title, :description, :available_date
  validates_numericality_of :price
  validates_uniqueness_of :title

  def self.salable_items
    find(:all,
         :conditions=>"available_date<=now()",
         :order=>"available_date desc"
        )
  end

  protected
  def validate
    errors.add(:price,"should be positive") unless price.nil? || price>=0.1
  end

end
